﻿using System;
using System.Collections.Generic;

namespace HeroldIT.Dnn.Modules.News
{
    public abstract class DataProvider
    {
        #region static properties

        private static readonly object instanceLock = new object();

        private static DataProvider instance;

        public static DataProvider Instance
        {
            get
            {
                if (null == instance)
                {
                    lock (instanceLock)
                    {
                        if (null == instance)
                        {
                            instance = DotNetNuke.Framework.Reflection.CreateObject("data", "HeroldIT.Dnn.Modules.News", "HeroldIT.Dnn.Modules.News") as DataProvider;
                        }
                    }
                }
                return instance;
            }
        }

        #endregion

        #region abstract methods

        public abstract int StoreNewsEntry(int moduleId, NewsEntry newsEntry);
        public abstract void DeleteNewsEntry(int moduleId, int newsEntryId);
        public abstract NewsEntry ReadNewsEntry(int moduleId, int newsEntryId);
        public abstract NewsEntry ReadNewsEntry(int moduleId, int newsEntryId, string locale, string fallbackLocale);

        public abstract IList<NewsEntry> ExportNewsEntries(int moduleId);

        public virtual PagedList<NewsEntry> ReadNewsEntries(int moduleId, string locale, string fallbackLocale, int skip, int take)
        {
            return this.ReadNewsEntries(moduleId, locale, fallbackLocale, skip, take, false);
        }

        public virtual PagedList<NewsEntry> ReadNewsEntries(int moduleId, ICollection<string> categories, string locale, string fallbackLocale, int skip, int take)
        {
            return this.ReadNewsEntries(moduleId, categories, locale, fallbackLocale, skip, take, false);
        }

        public virtual PagedList<NewsEntry> ReadNewsEntries(int moduleId, string locale, string fallbackLocale, int skip, int take, bool allEntries)
        {
            return this.FindNewsEntries(moduleId, null, locale, fallbackLocale, skip, take, allEntries);
        }

        public virtual PagedList<NewsEntry> ReadNewsEntries(int moduleId, ICollection<string> categories, string locale, string fallbackLocale, int skip, int take, bool allEntries)
        {
            return this.FindNewsEntries(moduleId, categories, null, locale, fallbackLocale, skip, take, allEntries);
        }

        public virtual PagedList<NewsEntry> FindNewsEntries(int moduleId, string filterText, string locale,
                                                             string fallbackLocale, int skip, int take)
        {
            return this.FindNewsEntries(moduleId, filterText, locale, fallbackLocale, skip, take, false);
        }

        public virtual PagedList<NewsEntry> FindNewsEntries(int moduleId, ICollection<string> categories, string filterText, string locale,
                                                             string fallbackLocale, int skip, int take)
        {
            return this.FindNewsEntries(moduleId, categories, filterText, locale, fallbackLocale, skip, take, false);
        }

        public virtual PagedList<NewsEntry> FindNewsEntries(int moduleId, string filterText, string locale,
                                                             string fallbackLocale, int skip, int take, bool allEntries)
        {
            return this.FindNewsEntries(moduleId, null, filterText, locale, fallbackLocale, skip, take, allEntries);
        }

        public virtual PagedList<NewsEntry> FindNewsEntries(int moduleId, ICollection<string> categories, string filterText, string locale,
                                                     string fallbackLocale, int skip, int take, bool allEntries)
        {
            return this.FindNewsEntries(moduleId, categories, filterText, null, null, locale, fallbackLocale, skip, take,
                                        allEntries);
        }

        public abstract PagedList<NewsEntry> FindNewsEntries(int moduleId, ICollection<string> categories, string filterText, DateTime? from,
                                                     DateTime? until, string locale, string fallbackLocale, int skip, int take, bool allEntries);

        public abstract IEnumerable<string> ReadTeaserImageNames(int moduleId);
        public abstract IEnumerable<string> ReadDetailImageNames(int moduleId);
        public abstract IEnumerable<string> ReadCategories(int moduleId);
        public abstract IEnumerable<string> ReadLocales(int moduleId);

        //public abstract int AddAnnouncementItem(int announcementID, string locale, string createdByUser, string title, string uRL, string summary, string content, string ImageFile);
        //public abstract int AddNewAnnouncement(int moduleID, string locale, string createdByUser, string title, string uRL, DateTime expireDate, string summary, string content, int viewOrder, string ImageFile, DateTime publishDate);
        //public abstract void DeleteAnnouncementItem(int AnnouncementID, string Locale);
        //public abstract void DeleteAnnouncements(int AnnouncementID);
        //public abstract IDataReader GetLocales(int moduleID);
        //public abstract IDataReader GetAnnouncement(int AnnouncementID, int moduleId, string locale);
        //public abstract IDataReader GetAnnouncements(int moduleID, string locale, int PortalID, int archiveType, string OrderByField);
        //public abstract IDataReader GetAnnouncementsReport(int moduleID);
        //public abstract IDataReader GetOtherLocales(int announcementID, string locale);
        //public abstract void UpdateAnnouncements(int AnnouncementID, string locale, string createdByUser, string title, string uRL, DateTime expireDate, string summary, string content, int viewOrder, string ImageFile, DateTime publishDate);

        #endregion
    }
}
